/*
Copyright 2011 Francisco Nieto Raya

This program is free software: you can redistribute it and/or modify it under the terms of the Apache Software License 
as published by the Free Software Foundation, either version 2.0 of the License, or (at your option) any later version.

This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation.
For more information on the Apache Software Foundation, please see <http://www.apache.org/>.

*/

#include <stdio.h>
#include <stdlib.h>
#include "gd.h"
#include "imag.h"

int main(int argc,char *argv[]){
    gdImagePtr im,imag;
    FILE *fix;
    imagen *img,*I,*IMG;
    if (argc<4){
       perror ("El formato es:\n nom programa %s imagen %s Img.base %s Img.resultado");
       exit (1);
    }
    im=abrirImagen(argv[1]);
    img=deImagePtr(im);
    imag=abrirImagen(argv[2]);
    I=deImagePtr(imag);
    if ((img->fil>I->fil)||(img->col>I->col)){
       perror ("El tamaño de la imagen base tiene que ser mayor que la o igual que la original");
       exit(1);                                       
    }
    conv_gris(im,img);
    gdImageDestroy(im);
    borrador(img);
    IMG=adaptador(I,img);
    fusion(IMG,img);
    im=deImagen(img);
    escribirImagen(argv[3],im);
    gdImageDestroy(im);
    liberarImagen(img);
    gdImageDestroy(imag);
    liberarImagen(IMG);
    liberarImagen(I);
    return 0;
    }
